﻿#include "lvgl_radio_anim.h"


//----后台开关----//
void lvgl_radio_anim_background_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_radio_anim_background_ready_cb(lv_anim_t* anim)
{
    lvgl_radio_anim_debug("anim in ready");

}

void lvgl_radio_anim_background_start(int start, int end)
{
#if LVGL_ANIM_SWITCH


    lvgl_radio_anim_debug("anim in start");


    lv_anim_path_init(&lvgl_radio_data.anim_path_in);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_in, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_radio_data.anim_background);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_background, lvgl_radio_anim_background_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_background, lvgl_radio_anim_background_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_background, start,end);
    lv_anim_set_time(&lvgl_radio_data.anim_background, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_background, lvgl_radio_data.image_background);

    lv_anim_set_path(&lvgl_radio_data.anim_background, &lvgl_radio_data.anim_path_in);
    lv_anim_start(&lvgl_radio_data.anim_background);

#else


    lvgl_radio_anim_background_ready_cb(NULL);

#endif

}
//----后台开关----//


//----保存电台----//
void lvgl_radio_anim_save_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_radio_anim_save_ready_cb(lv_anim_t* anim)
{

    lvgl_radio_anim_debug("anim in ready");


}

void lvgl_radio_anim_save_start(int start, int end)
{
#if LVGL_ANIM_SWITCH



    lvgl_radio_anim_debug("anim in start");

    lv_anim_path_init(&lvgl_radio_data.anim_path_in);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_in, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_radio_data.anim_save);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_save, lvgl_radio_anim_save_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_save, lvgl_radio_anim_save_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_save, start,end);
    lv_anim_set_time(&lvgl_radio_data.anim_save, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_save, lvgl_radio_data.image_save);

    lv_anim_set_path(&lvgl_radio_data.anim_save, &lvgl_radio_data.anim_path_in);
    lv_anim_start(&lvgl_radio_data.anim_save);

#else


    lvgl_radio_anim_save_ready_cb(NULL);

#endif

}
//----保存电台----//


//----选择P----//
void lvgl_radio_anim_p_pos_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_x(arc, v);
}

void lvgl_radio_anim_p_pos_ready_cb(lv_anim_t* anim)
{

    lvgl_radio_anim_debug("anim in ready");


}

void lvgl_radio_anim_p_pos_start(int targetpos)
{
#if LVGL_ANIM_SWITCH


    lvgl_radio_anim_debug("anim in start");


    lv_anim_path_init(&lvgl_radio_data.anim_path_p_pos);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_p_pos, lv_anim_path_bounce);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_radio_data.anim_p_pos);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_p_pos, lvgl_radio_anim_p_pos_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_p_pos, lvgl_radio_anim_p_pos_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_p_pos, lv_obj_get_x(lvgl_radio_data.cont_p), targetpos);
    lv_anim_set_time(&lvgl_radio_data.anim_p_pos, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_p_pos, lvgl_radio_data.cont_p);

    lv_anim_set_path(&lvgl_radio_data.anim_p_pos, &lvgl_radio_data.anim_path_p_pos);
    lv_anim_start(&lvgl_radio_data.anim_p_pos);

#else
    lvgl_radio_anim_p_pos_ready_cb(NULL);
    lv_obj_set_x(lvgl_radio_data.cont_p,targetpos);
#endif

}
//----选择P----//




void lvgl_radio_anim_in_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_radio_anim_in_ready_cb(lv_anim_t* anim)
{

    lvgl_radio_anim_debug("anim in ready");


    lv_obj_set_pos(lvgl_radio_data.cont_main, 0, 0);

    lvgl_group_add_obj(&lvgl_radio_data.cont_main);
    lvgl_group_focus_obj(&lvgl_radio_data.cont_main);
    lvgl_send_event(&lvgl_radio_data.cont_main, CZ_EVENT_ANIM_IN_READY, NULL);
}

void lvgl_radio_anim_in_start(int mode, int time)
{
#if LVGL_ANIM_SWITCH




    lvgl_radio_anim_debug("anim in start");

    lv_anim_path_init(&lvgl_radio_data.anim_path_in);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_in, LVGL_ANIM_IN_PATH);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_radio_data.anim_in);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_in, lvgl_radio_anim_in_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_in, lvgl_radio_anim_in_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_in, lv_obj_get_y(lvgl_radio_data.cont_main), 0);
    lv_anim_set_time(&lvgl_radio_data.anim_in, LVGL_ANIM_IN_TIME);
    lv_anim_set_var(&lvgl_radio_data.anim_in, lvgl_radio_data.cont_main);

    lv_anim_set_path(&lvgl_radio_data.anim_in, &lvgl_radio_data.anim_path_in);
    lv_anim_start(&lvgl_radio_data.anim_in);

#else


    lvgl_radio_anim_in_ready_cb(NULL);

#endif

}


void lvgl_radio_anim_out_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}
void lvgl_radio_anim_out_ready_cb(lv_anim_t* anim)
{

    lvgl_radio_anim_debug("anim out ready");



    lvgl_send_event(&lvgl_radio_data.cont_main, CZ_EVENT_ANIM_OUT_READY, NULL);
    lvgl_radio_close();

}

void lvgl_radio_anim_out_start(int mode, int time)
{

    lvgl_group_remove_obj(&lvgl_radio_data.cont_main);

#if LVGL_ANIM_SWITCH



    lvgl_radio_anim_debug("anim out start");

    lv_anim_path_init(&lvgl_radio_data.anim_path_out);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_out, LVGL_ANIM_OUT_PATH);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

    lv_anim_init(&lvgl_radio_data.anim_out);
    lv_anim_set_exec_cb(&lvgl_radio_data.anim_out, lvgl_radio_anim_out_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_out, lvgl_radio_anim_out_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_out, lv_obj_get_y(lvgl_radio_data.cont_main), lv_obj_get_height(lv_scr_act()));
    lv_anim_set_time(&lvgl_radio_data.anim_out, LVGL_ANIM_OUT_TIME);
    lv_anim_set_var(&lvgl_radio_data.anim_out, lvgl_radio_data.cont_main);

    lv_anim_set_path(&lvgl_radio_data.anim_out, &lvgl_radio_data.anim_path_out);
    lv_anim_start(&lvgl_radio_data.anim_out);

#else


    lvgl_radio_anim_out_ready_cb(NULL);

#endif

}



//----select anim----//
void lvgl_radio_anim_select_x_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_x(arc, v);
}

void lvgl_radio_anim_select_x_ready_cb(lv_anim_t* anim)
{
    lvgl_radio_anim_debug("anim select_x ready");
}

void lvgl_radio_anim_select_x_start(int targetpos)
{
#if LVGL_ANIM_SWITCH


    lvgl_radio_anim_debug("anim select_x start");


    lv_anim_path_init(&lvgl_radio_data.anim_path_select_x);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_select_x, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_radio_data.anim_select_x);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_select_x, lvgl_radio_anim_select_x_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_select_x, lvgl_radio_anim_select_x_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_select_x, lv_obj_get_x(lvgl_radio_data.cont_select), targetpos);
    lv_anim_set_time(&lvgl_radio_data.anim_select_x, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_select_x, lvgl_radio_data.cont_select);

    lv_anim_set_path(&lvgl_radio_data.anim_select_x, &lvgl_radio_data.anim_path_select_x);
    lv_anim_start(&lvgl_radio_data.anim_select_x);

#else

    lv_obj_set_x(lvgl_radio_data.cont_main, targetpos);

#endif

}


void lvgl_radio_anim_select_y_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_radio_anim_select_y_ready_cb(lv_anim_t* anim)
{

    lvgl_radio_anim_debug("anim select_y ready");


}

void lvgl_radio_anim_select_y_start(int targetpos)
{
#if LVGL_ANIM_SWITCH


    lvgl_radio_anim_debug("anim select_y start");

    lv_anim_path_init(&lvgl_radio_data.anim_path_select_y);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_select_y, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）



    lv_anim_init(&lvgl_radio_data.anim_select_y);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_select_y, lvgl_radio_anim_select_y_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_select_y, lvgl_radio_anim_select_y_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_select_y, lv_obj_get_y(lvgl_radio_data.cont_select), targetpos);
    lv_anim_set_time(&lvgl_radio_data.anim_select_y, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_select_y, lvgl_radio_data.cont_select);

    lv_anim_set_path(&lvgl_radio_data.anim_select_y, &lvgl_radio_data.anim_path_select_y);
    lv_anim_start(&lvgl_radio_data.anim_select_y);

#else

    lv_obj_set_y(lvgl_radio_data.cont_main, targetpos);

#endif

}

void lvgl_radio_anim_select_w_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_width(arc, v);
}

void lvgl_radio_anim_select_w_ready_cb(lv_anim_t* anim)
{
    lvgl_radio_anim_debug("anim select_w ready");



}

void lvgl_radio_anim_select_w_start(int targetpos)
{
#if LVGL_ANIM_SWITCH


    lvgl_radio_anim_debug("anim select_w start");

    lv_anim_path_init(&lvgl_radio_data.anim_path_select_w);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_select_w, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_radio_data.anim_select_w);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_select_w, lvgl_radio_anim_select_w_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_select_w, lvgl_radio_anim_select_w_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_select_w, lv_obj_get_width(lvgl_radio_data.cont_select), targetpos);
    lv_anim_set_time(&lvgl_radio_data.anim_select_w, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_select_w, lvgl_radio_data.cont_select);

    lv_anim_set_path(&lvgl_radio_data.anim_select_w, &lvgl_radio_data.anim_path_select_w);
    lv_anim_start(&lvgl_radio_data.anim_select_w);

#else

    lv_obj_set_width(lvgl_radio_data.cont_main, targetpos);

#endif

}


void lvgl_radio_anim_select_h_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_height(arc, v);
}

void lvgl_radio_anim_select_h_ready_cb(lv_anim_t* anim)
{
    lvgl_radio_anim_debug("anim select_h ready");




}

void lvgl_radio_anim_select_h_start(int targetpos)
{
#if LVGL_ANIM_SWITCH



    lvgl_radio_anim_debug("anim select_h start");


    lv_anim_path_init(&lvgl_radio_data.anim_path_select_h);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_select_h, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）



    lv_anim_init(&lvgl_radio_data.anim_select_h);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_select_h, lvgl_radio_anim_select_h_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_select_h, lvgl_radio_anim_select_h_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_select_h, lv_obj_get_height(lvgl_radio_data.cont_select), targetpos);
    lv_anim_set_time(&lvgl_radio_data.anim_select_h, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_select_h, lvgl_radio_data.cont_select);

    lv_anim_set_path(&lvgl_radio_data.anim_select_h, &lvgl_radio_data.anim_path_select_h);
    lv_anim_start(&lvgl_radio_data.anim_select_h);

#else

    lv_obj_set_height(lvgl_radio_data.cont_main, targetpos);

#endif

}

//----select anim----//





//----音量----//
void lvgl_radio_anim_vol_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_x(arc, v);
}

void lvgl_radio_anim_vol_ready_cb(lv_anim_t* anim)
{
    lvgl_radio_anim_debug("anim vol ready");
}

void lvgl_radio_anim_vol_start(int start, int end)
{
#if LVGL_ANIM_SWITCH


    lvgl_radio_anim_debug("anim vol start");


    lv_anim_path_init(&lvgl_radio_data.anim_path_vol);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_vol, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_radio_data.anim_vol);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_vol, lvgl_radio_anim_vol_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_vol, lvgl_radio_anim_vol_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_vol, start, end);
    lv_anim_set_time(&lvgl_radio_data.anim_vol, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_vol, lvgl_radio_data.cont_vol);

    lv_anim_set_path(&lvgl_radio_data.anim_vol, &lvgl_radio_data.anim_path_vol);
    lv_anim_start(&lvgl_radio_data.anim_vol);

#else
    lvgl_radio_anim_vol_ready_cb(NULL);
    lv_obj_set_x(lvgl_radio_data.cont_vol, end);
#endif
}

//----音量----//


//----信号----//
void lvgl_radio_anim_sig_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_x(arc, v);
}

void lvgl_radio_anim_sig_ready_cb(lv_anim_t* anim)
{
    lvgl_radio_anim_debug("anim sig ready");


}

void lvgl_radio_anim_sig_start(int start, int end)
{
#if LVGL_ANIM_SWITCH



    lvgl_radio_anim_debug("anim sig start");


    lv_anim_path_init(&lvgl_radio_data.anim_path_sig);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_sig, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

    lv_anim_init(&lvgl_radio_data.anim_sig);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_sig, lvgl_radio_anim_sig_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_sig, lvgl_radio_anim_sig_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_sig, start, end);
    lv_anim_set_time(&lvgl_radio_data.anim_sig, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_sig, lvgl_radio_data.cont_sig);

    lv_anim_set_path(&lvgl_radio_data.anim_sig, &lvgl_radio_data.anim_path_sig);
    lv_anim_start(&lvgl_radio_data.anim_sig);

#else
    lvgl_radio_anim_sig_ready_cb(NULL);
    lv_obj_set_x(lvgl_radio_data.cont_vol, end);
#endif
}

//----信号----//


//----频率----//
void lvgl_radio_anim_frequency_cb(void* arc, lv_anim_value_t v)
{
    lvgl_radio_set_frequency(v);
}

void lvgl_radio_anim_frequency_ready_cb(lv_anim_t* anim)
{
    lvgl_radio_anim_debug("anim frequency ready");


    lvgl_radio_detect_p(lv_label_get_text(lvgl_radio_data.label_frequency));

}

void lvgl_radio_anim_frequency_start(int start, int end)
{
#if LVGL_ANIM_SWITCH


    lvgl_radio_anim_debug("anim frequency start");


    lv_anim_path_init(&lvgl_radio_data.anim_path_frequency);
    lv_anim_path_set_cb(&lvgl_radio_data.anim_path_frequency, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_radio_data.anim_frequency);


    lv_anim_set_exec_cb(&lvgl_radio_data.anim_frequency, lvgl_radio_anim_frequency_cb);
    lv_anim_set_ready_cb(&lvgl_radio_data.anim_frequency, lvgl_radio_anim_frequency_ready_cb);
    lv_anim_set_values(&lvgl_radio_data.anim_frequency, start, end);
    lv_anim_set_time(&lvgl_radio_data.anim_frequency, 500);
    lv_anim_set_var(&lvgl_radio_data.anim_frequency, lvgl_radio_data.label_frequency);

    lv_anim_set_path(&lvgl_radio_data.anim_frequency, &lvgl_radio_data.anim_path_frequency);
    lv_anim_start(&lvgl_radio_data.anim_frequency);

#else
    lvgl_radio_anim_frequency_ready_cb(NULL);
    lvgl_radio_set_frequency(end);
#endif
}

//----频率----//
